package com.kdtech.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;


public class SerializeUtils {
	public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException {
		ObjectInputStream i = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data)));
		return i.readObject();
	}

	public static byte[] serialize(Serializable obj) throws IOException {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream b = new ObjectOutputStream(new GZIPOutputStream(bos));
		b.writeObject(obj);
		b.close();
		bos.close();
		return bos.toByteArray();
	}
}
